{% extends "base_generic.html" %}
{% load static %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header bg-primary text-white">
            <h1 class="mb-0"><i class="fas fa-book"></i> 编辑书籍副本 - {{ form.instance.book.title }}</h1>
        </div>
        <div class="card-body">
            <form action="" method="post">
                {% csrf_token %}
                <input type="hidden" name="book" value="{{ form.instance.book.id }}">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label for="id_imprint" class="form-label">版本信息:</label>
                        <input type="text" id="id_imprint" name="imprint" class="form-control" value="{{ form.instance.imprint|default:'' }}">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label for="id_due_back" class="form-label">预计归还日期:</label>
                        <input type="date" id="id_due_back" name="due_back" class="form-control" value="{{ form.instance.due_back|date:'Y-m-d'|default:'' }}">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label for="id_status" class="form-label">状态:</label>
                        <select id="id_status" name="status" class="form-select" required>
                            {% for value, label in form.status.field.choices %}
                                <option value="{{ value }}" {% if form.instance.status == value %}selected{% endif %}>{{ label }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label for="id_borrower" class="form-label">借阅者:</label>
                        <select id="id_borrower" name="borrower" class="form-select">
                            <option value="">---------</option>
                            {% for borrower in form.borrower.field.queryset %}
                                <option value="{{ borrower.id }}" {% if form.instance.borrower.id == borrower.id %}selected{% endif %}>{{ borrower.username }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="text-end">
                    <a href="{% url 'bookinstances' %}" class="btn btn-secondary">取消</a>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}